package daohibernate;

import java.util.List;
import java.util.Set;

import hibernate.HibernateUtil;
import negocio.beans.central.MovimientoStock;
import negocio.beans.central.Proveedor;
import negocio.beans.oficinaventa.Rodamiento;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class MovimientoStockDAO {

	private static MovimientoStockDAO instancia = null;
	private static SessionFactory sf = null;
	
	public static MovimientoStockDAO getInstancia(){
		if(instancia == null){
			sf = HibernateUtil.getSessionFactory();
			instancia = new MovimientoStockDAO();
		} 
		return instancia;
	}
	
	
	public void BorrarMovStock(MovimientoStock p){		
		Session s = sf.openSession();
		s.beginTransaction();
		
		
		s.delete(p);
		
		s.flush();
		
		s.getTransaction().commit();
		s.close();
	}
	
	public void altaMovimientoStock(MovimientoStock ms){
		Session s = sf.openSession();
		s.beginTransaction();
		
		s.persist(ms);
		
		s.flush();
		s.getTransaction().commit();
	}
	
	public List<MovimientoStock> buscarMovStockPorCodigoStock(int cod)
	{
		Session s = sf.openSession();

		@SuppressWarnings("unchecked")
		List<MovimientoStock> lst =  s.createQuery("from MovimientoStock where stock = " + cod ).list();
		s.close();
		
		
		return lst;
	}
	
}
